﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using House.Server.Dto;

namespace House.Server.Repository
{
    public class System_MenuInfoRepository: GenericBaseRepository<MenuInfo>
    {

        /// <summary>
        /// 根据父节点查询信息
        /// </summary>
        /// <param name="ParentID">父节点</param>
        /// <returns></returns>
        public List<MenuInfo> MenuInfoSelectByParentID(int ParentID)
        {
            List<MenuInfo> list = new List<MenuInfo>();

            string sql = @"select * from t_MenuInfo where ParentID=@ParentID";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@ParentID";
                    p.Value = ParentID;
                    cmd.Parameters.Add(p);
                    var x = cmd.ExecuteReader();

                    try
                    {
                        while (x.Read())
                        {
                            MenuInfo MenuModel = new MenuInfo();
                            MenuModel.MenuId = Convert.ToInt32(x["MenuId"]);
                            MenuModel.MenuName = x["MenuName"].ToString();
                            MenuModel.MenuUrl = x["MenuUrl"].ToString();
                            MenuModel.ParentID = Convert.ToInt32(x["ParentID"]);
                            MenuModel.MenuFormID = x["MenuFormID"].ToString();
                            MenuModel.MenuMark = x["MenuMark"].ToString();

                            list.Add(MenuModel);
                        }
                    }
                    finally
                    {
                        x.Close();
                    }
                }
                return list;
            }
        }

    }
}
